using System.Runtime.Loader;
using System.Text.Json.Serialization;
using HZY.Framework.DependencyInjection;
using Rougamo.Context;
using Rougamo;
using Newtonsoft.Json;
using HZY.Framework.DependencyInjection.SourceGenerator.Test;

var builder = WebApplication.CreateSlimBuilder(args);

builder.Services.ConfigureHttpJsonOptions(options =>
{
    options.SerializerOptions.TypeInfoResolverChain.Insert(0, AppJsonSerializerContext.Default);
});

builder.Services.AddDependencyInjectionHZYFrameworkDependencyInjectionSourceGeneratorTest();

builder.Services.AddDependencyInjection(AssemblyLoadContext.Default.Assemblies.ToList());

var app = builder.Build();

var sampleTodos = new Todo[] {
    new(1, "Walk the dog"),
    new(2, "Do the dishes", DateOnly.FromDateTime(DateTime.Now)),
    new(3, "Do the laundry", DateOnly.FromDateTime(DateTime.Now.AddDays(1))),
    new(4, "Clean the bathroom"),
    new(5, "Clean the car", DateOnly.FromDateTime(DateTime.Now.AddDays(2)))
};

var todosApi = app.MapGroup("/todos");
todosApi.MapGet("/", () => sampleTodos);
todosApi.MapGet("/{id}", (int id) =>
    sampleTodos.FirstOrDefault(a => a.Id == id) is { } todo
        ? Results.Ok(todo)
        : Results.NotFound());

using var a = app.Services.CreateScope();
var _UserService = a.ServiceProvider.GetService<UserService>();
await _UserService.GetName("123");

var testService = a.ServiceProvider.GetService<TestService>();
var userServiceString = testService?.getUserService();

var str = JsonConvert.SerializeObject("123");

//
var aa = new a();
var bb = new b<int>();

var c = bb.c;
var cc = aa.c;


app.Run();

public class b<T>
{
    [X]
    public T c { get; set; }
}

public class a : b<int>
{

}

public class XAttribute : MoAttribute
{
    public override void OnEntry(MethodContext context)
    {
        Console.WriteLine($"[OnEntry] {context.Method.Name}");
    }
}



public record Todo(int Id, string? Title, DateOnly? DueBy = null, bool IsComplete = false);

[JsonSerializable(typeof(Todo[]))]
internal partial class AppJsonSerializerContext : JsonSerializerContext
{

}

